package cn.wolfcode.luowowo.article.service.impl;

import cn.wolfcode.luowowo.article.domain.ViewpointComment;
import cn.wolfcode.luowowo.article.mapper.ViewpointCommentMapper;
import cn.wolfcode.luowowo.article.service.IViewpointCommentService;
import cn.wolfcode.luowowo.comment.domain.ViewpointRefComment;
import cn.wolfcode.luowowo.comment.service.IViewpointRefCommentService;
import cn.wolfcode.luowowo.common.query.ViewpointCommentQueryObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.List;

@Service
public class ViewpointCommentServiceImpl implements IViewpointCommentService {
    @Autowired
    private ViewpointCommentMapper viewpointCommentMapper;
    @Reference
    private IViewpointRefCommentService viewpointRefCommentService;


    public PageInfo query(ViewpointCommentQueryObject qo) {
        qo.setOrderBy("createTime desc");
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(),qo.getOrderBy());
        List<ViewpointComment> list = viewpointCommentMapper.selectForList(qo );
        PageInfo pageInfo = new PageInfo(list);
        List<ViewpointComment> pageInfoList = pageInfo.getList();
        for (ViewpointComment vc : pageInfoList) {
          List<ViewpointRefComment> refComments = viewpointRefCommentService.listRefCommentsByCommentId(vc.getId());
          vc.setRefComments(refComments);
        }
        pageInfo.setList(pageInfoList);
        return pageInfo;
    }

    //有图的评论数量
    public int hasImageNum(Long pointId) {
        return viewpointCommentMapper.selectHasImageNum(pointId);
    }

    //好评的数量
    public int goodNum(Long pointId) {
        return viewpointCommentMapper.selectGoodNum(pointId);
    }

    //中评数量
    public int averageNum(Long pointId) {
        return viewpointCommentMapper.selectAverageNum(pointId);
    }

    //差评数量
    public int badNum(Long pointId) {
        return viewpointCommentMapper.selectBadNum(pointId);
    }

    //添加景点评论
    public void addComment(ViewpointComment viewpointComment) {
        viewpointComment.setCreateTime(new Date());
        viewpointCommentMapper.insert(viewpointComment);

    }




}
